//
//  SellSelectTypeViewController.m
//  ZhuiKe55like
//
//  Created by junseek on 15/12/2.
//  Copyright (c) 2015年 五五来客 李江. All rights reserved.
//

#import "SellSelectTypeViewController.h"
#import "RHTableView.h"

@interface SellSelectTypeViewController (){
    RHTableView *tableViewT;
    NSMutableArray *selectArray;
    NSArray *arrayAllData;
}

@end

@implementation SellSelectTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initComponents];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];    
    [tableViewT cancelDownload];
}


- (void)initComponents{
   
    selectArray=[[NSMutableArray alloc] initWithArray:[self.otherInfo objectForJSONKey:@"selectArray"]];
    arrayAllData=[self.otherInfo objectForJSONKey:@"list"];
    
    tableViewT=[[RHTableView alloc]initWithFrame:CGRectMake(0, kTopHeight, kScreenWidth, kContentHeight)];
    [tableViewT showRefresh:NO LoadMore:NO];
    tableViewT.delegate = self;
    tableViewT.dataSource = self;
//    tableViewT.delegate2=self;
    [tableViewT setBackgroundColor:[UIColor clearColor]];
    [tableViewT setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:tableViewT];
    [tableViewT setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
    
  
}

#pragma mark tableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return arrayAllData.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic= [arrayAllData objectAtIndex:indexPath.row];
    
//    DLog(@"_____%@",dic);
    static NSString *identifier =@"cell_identifier";// dic.description.md5;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.backgroundColor=[UIColor clearColor];
        
        UIView *BGV=[[UIView alloc]initWithFrame:cell.bounds];
        [BGV setBackgroundColor:[UIColor whiteColor]];
        [cell setBackgroundView: BGV];
                
        UILabel *lblName=[RHMethods labelWithFrame:CGRectMake(20, 12, kScreenWidth-70, 20) font:fontTitle color:rgbTitleColor text:[dic valueForJSONStrKey:@"name"]];//
        lblName.tag=101;
        [cell addSubview:lblName];
        
        UIImageView *imageV=[RHMethods imageviewWithFrame:CGRectMake(kScreenWidth-60, 0, 60, 44) defaultimage:@"radioC20151128" contentMode:UIViewContentModeCenter];
        imageV.tag=102;
        [cell addSubview:imageV];
        
        
        UIImageView *cellLine=[RHMethods imageviewWithFrame:CGRectMake(0, 43.5, kScreenWidth, 0.5) defaultimage:@"userLine"];
        [cellLine setContentMode:UIViewContentModeScaleAspectFill];
//        cellLine.alpha=0.2;
        [cell addSubview:cellLine];
        
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    UILabel *lblName=(UILabel *)[cell viewWithTag:101];
    lblName.text=[dic valueForJSONStrKey:@"name"];
    UIImageView *imageV=(UIImageView *)[cell viewWithTag:102];
    if ([self.userInfo isEqualToString:@"UpdateUserDataViewController"] && [selectArray containsObject:[dic valueForJSONStrKey:@"name"]]) {
        imageV.hidden=NO;
        lblName.textColor=rgbpublicColor;
    }else if ([self.userInfo isEqualToString:@"AddLicensePlateViewController"] && [selectArray containsObject:[dic valueForJSONStrKey:@"id"]]) {
        imageV.hidden=NO;
        lblName.textColor=rgbpublicColor;
    }else{
        lblName.textColor=rgbTitleColor;//[UIColor whiteColor];
        imageV.hidden=YES;
    }
    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic= [arrayAllData objectAtIndex:indexPath.row];
//    [selectArray removeAllObjects];
//    [selectArray addObject:[dic valueForJSONStrKey:@"id"]];
//    [tableViewT reloadData];
    if ([self.userInfo isEqualToString:@"UpdateUserDataViewController"]) {
        [self popController:@"UpdateUserDataViewController" withSel:@selector(popRefreshType:) withObj:dic];
    }else if ([self.userInfo isEqualToString:@"AddLicensePlateViewController"]) {
         [self popController:self.userInfo withSel:@selector(popRefreshType:) withObj:dic];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
